import {createWebHistory, createRouter} from "vue-router"
import routes from "./routes"
import useTabsStore from "../store/tabs"
import useUserStore from "../store/useUserStore"

let tabsStore:any = undefined

const router = createRouter({
    history: createWebHistory(),
    routes,
})

// 进入页面前触发
router.beforeEach((to) => {
    if (!tabsStore){
        tabsStore = useTabsStore()
    }
    tabsStore.addTab({
        path: to.path,
        title:to.meta?.title??'未命名',
    })
})

// 设置白名单，白名单中的路由不需要登录验证
const whiteList = ['/login']

// 进入路由前判断是否登录
router.beforeEach((to)=>{
    if(!useUserStore)
    // 判断是否在白名单中
    if (!whiteList.includes(to.path)){
        // 判断是否登录
        
    }
})

export default router